﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TuringVM.Core
{
    public class CommandSet
    {
        private CommandBase[] _commands = new CommandBase[256];
        private Dictionary<string, CommandBase> _byName = new Dictionary<string, CommandBase>();

        public CommandBase this[byte code]
        {
            get { return _commands[code]; }
        }

        public CommandBase this[string name]
        {
            get { return _byName[name]; }
        }

        public CommandSet Add(params CommandBase[] commands)
        {
            foreach (var current in commands)
            {
                _commands[current.Code] = current;
                _byName.Add(current.Name, current);
            }
            return this;
        }
    }
}
